const char defaultVtx[] =
	"uniform mat4 uWorld;\n"
	"uniform mat4 uView;\n"
	"uniform mat4 uProjection;\n"

	"attribute vec4 aPosition;\n"
	"attribute vec3 aNormal;\n"
	"attribute vec3 aColor;\n"
	"attribute vec2 aTexCoord;\n"

	"varying vec3 vColor;\n"
	"varying vec3 vNormal;\n"
	"varying vec2 vTexCoord;\n"
	"varying vec2 vDepth;\n"
    "void main() \n"
	"{\n"
	"    mat4 wvp = uProjection * (uView * uWorld);\n"
    "    vec4 pos = wvp*vec4(aPosition.xyz, 1);\n"

	"    vColor = vec3(1.0, 1.0, 1.0);\n"
	"    vNormal = mat3(uWorld) * aNormal;\n"
	//"    vTexCoord = aTexCoord;\n"
	"    vTexCoord = aPosition.xz/100.0;\n"
	"	 vDepth = pos.zw;\n"
	"	 gl_Position = pos;\n"
    "}\n";

const char defaultFrag[] =
	"precision mediump float;\n"
	"uniform sampler2D texture;\n"

	"uniform vec3 uLightDir;\n"

	"varying vec3 vColor;\n"
	"varying vec3 vNormal;\n"
	"varying vec2 vTexCoord;\n"
	"varying vec2 vDepth;\n"
    "void main() \n"
	"{\n"
	//"    float light = max(dot(vNormal, normalize(uLightDir)), 0.0);\n"
	//"    vec4 texColor = texture2D(texture, vTexCoord);\n"
	//"    if (texColor.a < 0.5) discard;\n"
    //"    gl_FragColor = vec4(texColor.rgb * light, vDepth.x/vDepth.y);\n"
	"gl_FragColor = vec4(vTexCoord.xy, 0, 1);\n"
    "}\n";

const char particleVtx[] =
    "uniform mat4 uWorld;\n"
	"uniform mat4 uView;\n"
	"uniform mat4 uProjection;\n"

	"attribute vec4 aPosition;\n"
	"attribute vec2 aTexCoord;\n"

	"varying vec2 vTexCoord;\n"
	"varying vec2 vDepth;\n"
    "void main() \n"
	"{\n"
	"    mat4 wvp = uProjection * (uView * uWorld);\n"
    "    vec4 pos = wvp*vec4(aPosition.xyz, 1);\n"

	"    vTexCoord  = aTexCoord;\n"
	"	 vDepth     = pos.zw;\n"

	"	 gl_Position = pos;\n"
    "}\n";

const char particleFrag[] =
    "precision mediump float;\n"
	"uniform sampler2D texture;\n"
	"uniform vec4 uColor;\n"

	"varying vec2 vTexCoord;\n"
	"varying vec2 vDepth;\n"
    "void main() \n"
	"{\n"
	"    vec4 color = texture2D(texture, vTexCoord) * uColor;\n"
	"    if (color.a < 0.1) discard;"
    "    gl_FragColor = vec4(color.rgb, vDepth.x/vDepth.y);\n"
    "}\n";

const char islandVtx[] =
	"uniform mat4 uWorld;\n"
	"uniform mat4 uView;\n"
	"uniform mat4 uProjection;\n"

	"attribute vec4 aPosition;\n"
	"attribute vec3 aNormal;\n"
	"attribute vec2 aTexCoord;\n"

	"varying vec3 vNormal;\n"
	"varying vec2 vTexCoord;\n"
	"varying vec2 vDepth;\n"
	"varying vec3 vTexWeight;\n"
    "void main() \n"
	"{\n"
	"    mat4 wvp = uProjection * (uView * uWorld);\n"
    "    vec4 pos = wvp*vec4(aPosition.xyz, 1);\n"

	"    float h = aPosition.y;\n"
	"    vNormal    = mat3(uWorld) * aNormal;\n"
	"    vTexCoord  = aTexCoord;\n"
	"	 vDepth     = pos.zw;\n"

	"    vTexWeight = normalize(  vec3("
	"        clamp(1.0 - abs(h-2.0)/2.0,  0.0, 1.0),"		//beach
	"        clamp(1.0 - abs(h-5.0)/2.0,  0.0, 1.0),"		//grass
	"        clamp(1.0 - abs(h-7.0)/2.0,  0.0, 1.0)));\n"	//rock

	"	 gl_Position = pos;\n"
    "}\n";

const char islandFrag[] =
	"precision mediump float;\n"
	"uniform sampler2D texture_beach;\n"
	"uniform sampler2D texture_grass;\n"
	"uniform sampler2D texture_rock;\n"

	"uniform vec3 uLightDir;\n"

	"varying vec3 vNormal;\n"
	"varying vec2 vTexCoord;\n"
	"varying vec2 vDepth;\n"
	"varying vec3 vTexWeight;\n"
    "void main() \n"
	"{\n"
	"    float light = 0.5 + max(dot(vNormal, normalize(uLightDir)), 0.0)*0.5;\n"

	"    vec4 beachColor = texture2D(texture_beach, vTexCoord);\n"
	"    vec4 grassColor = texture2D(texture_grass, vTexCoord);\n"
	"    vec4 rockColor  = texture2D(texture_rock,  vTexCoord);\n"
	"	 vec4 color      = beachColor*vTexWeight.x+"
	"                      grassColor*vTexWeight.y+"
	"                      rockColor *vTexWeight.z;\n"

	"    gl_FragColor = vec4(color.rgb * light, vDepth.x/vDepth.y);\n"
    "}\n";

const char waterVtx[] =
	"uniform mat4 uWorld;\n"
	"uniform mat4 uView;\n"
	"uniform mat4 uProjection;\n"

	"attribute vec4 aPosition;\n"
	"attribute vec2 aTexCoord;\n"

	"varying vec2 vTexCoord;\n"
	"varying vec4 vRefraction;\n"
    "void main() \n"
	"{\n"
	"    mat4 wvp = uProjection * (uView * uWorld);\n"
	"	 vec4 pos = wvp*vec4(aPosition.xyz, 1);\n"

	"    vTexCoord = aTexCoord;\n"
	"	 vRefraction = pos;\n"
	"    gl_Position = pos;\n"
    "}\n";

const char waterFrag[] =
	"precision mediump float;\n"
	"uniform sampler2D bumpmap;\n"

	"uniform vec3 uLightDir;\n"

	"varying vec2 vTexCoord;\n"
	"varying vec4 vRefraction;\n"
    "void main() \n"
	"{\n"
	"	 vec3 normal = texture2D(bumpmap, vTexCoord).rgb - vec3(0.5, 0.5, 0.5);\n"
	"    float light = max(dot(normalize(normal), normalize(uLightDir)), 0.0);\n"

	/*"    vec2 refractTex = vec2("
	"		vRefraction.x/vRefraction.w/2.0 + 0.5, "
	"		vRefraction.y/vRefraction.w/2.0 + 0.5);\n"*/

	"    vec4 color = vec4(0.2, 0.1, 0.5, 1.0);\n"
    "    gl_FragColor = vec4(color.rgb * (0.5+0.5*light), vRefraction.z/vRefraction.w);\n"
    "}\n";

const char interfaceVtx[] =
	"attribute vec4 aPosition;\n"
	"attribute vec2 aTexCoord;\n"
	"varying vec2 vTexCoord;\n"
	"void main() \n"
	"{\n"
	"    vTexCoord = aTexCoord;\n"
	"    vec2 Pos = aPosition.xy * 2.0;\n"
	"    gl_Position = vec4(Pos.x - 1.0, 1.0 - Pos.y, aPosition.zw);\n"
	"}\n";

const char interfaceFrag[] =
	"precision mediump float;\n"
	"uniform sampler2D texture;\n"

	"varying vec2 vTexCoord;\n"
    "void main() \n"
	"{\n"
	"    vec4 texColor = texture2D(texture, vTexCoord);\n"
    "    gl_FragColor = texColor;\n"
    "}\n";

const char atmFrag[] =
    "precision mediump float;\n"
	"uniform sampler2D texture;\n"

	"varying vec2 vTexCoord;\n"
    "void main() \n"
	"{\n"
	"    vec4 col = texture2D(texture, vTexCoord);\n"
	"	 vec4 sky = vec4(1.0 - vTexCoord.y, 1.0 - vTexCoord.y, 1, 1)*(0.5 + 1.0-vTexCoord.y) - col;\n"

    "    gl_FragColor = vec4(col.rgb + sky.rgb*pow(col.a, 64.0), col.a);\n"
    "}\n";

const char blurFrag[] =
	"precision mediump float;\n"
	"uniform sampler2D texture;\n"
	"uniform vec2 texel;\n"

	"varying vec2 vTexCoord;\n"
    "void main() \n"
	"{\n"
    "    vec4 color = texture2D(texture, vTexCoord) * 0.6;\n"

	"    color += texture2D(texture, vTexCoord + texel    ) * 0.15;\n"
	"    color += texture2D(texture, vTexCoord + texel*2.0) * 0.05;\n"
	"    color += texture2D(texture, vTexCoord - texel    ) * 0.15;\n"
	"    color += texture2D(texture, vTexCoord - texel*2.0) * 0.05;\n"

	"	 gl_FragColor = vec4(color.rgb, 1);\n"
    "}\n";

const char DoFFrag[] =
	"precision mediump float;\n"
	"uniform sampler2D texture;\n"
	"uniform sampler2D blurMap;\n"

	"varying vec2 vTexCoord;\n"
    "void main() \n"
	"{\n"
    "    vec4 sharp = texture2D(texture, vTexCoord);\n"
	" 	 vec4 blur  = texture2D(blurMap, vTexCoord) - sharp;\n"
	"    vec4 dof   = vec4(sharp.rgb + blur.rgb*pow(sharp.a, 12.0), 1);\n"

	"	 gl_FragColor = dof;\n"
    "}\n";

const char faderFrag[] =
    "precision mediump float;\n"
    "uniform vec4 color;"
    "uniform int texture;"

	"varying vec2 vTexCoord;\n"
    "void main() \n"
	"{\n"
	"	 gl_FragColor = color;\n"
    "}\n";
